/*******************************************************************************
 * Copyright (c) 2009 L.Carbonnaux.
 *******************************************************************************/

package org.lcx.taskvision.core;

import java.util.Date;

import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.data.TaskData;
import org.eclipse.mylyn.tasks.core.data.TaskMapper;

/**
 * @author Laurent Carbonnaux
 */
public class TaskVisionTaskMapper extends TaskMapper {

	public TaskVisionTaskMapper(TaskData taskData) {
		super(taskData);
	}
	
//	@Override
//	public PriorityLevel getPriorityLevel() {
//		super.getPriorityLevel();
//		String value = getPriority();
//		return (value != null) ? PriorityLevel.fromDescription(value) : null;
//	}
//	

	@Override
	public boolean applyTo(ITask task) {
		boolean changed = super.applyTo(task);
		changed = changed | areSvNotEquals(task.getCompletionDate(), getCompletionDate());
		task.setCompletionDate(getCompletionDate());
		return changed;
	}

	private boolean areSvNotEquals(Object existingProperty, Object newProperty) {
		return (existingProperty != null) ? !existingProperty.equals(newProperty) : newProperty != null;
	}

	@Override
	public Date getCompletionDate() {
		// ScrumVision does not manage completion date, but completion status
		if(getStatus()==null) return null;
		if(getStatus().length()>0) return new Date(0);
		return null;
	}
	
//	@Override
//	public PriorityLevel getPriorityLevel() {
//			String priority = getPriority();
//			if(priority!=null && TASK_PRIORITY.getPriorityFromFeed(priority)!=null) {
//				String value = TASK_PRIORITY.getPriorityFromFeed(priority);
//				return PriorityLevel.fromString(value);
//			}
//			return PriorityLevel.getDefault();
//	}
//	
}
